package com.example.forum_system.controller;

import com.example.forum_system.common.AppResult;
import com.example.forum_system.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: 啵啵虎
 * @Date: 2024-05-14  17:17
 */

@Api(tags = "测试接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试打印")
    @GetMapping("/hello")
    public String hello(){
        return "hello,baekhyun...";
    }

    @ApiOperation("测试异常")
    @GetMapping("/testException")
    public AppResult testException() throws Exception {
        throw new Exception("这是一个Exception...");
    }

    @ApiOperation("测试自定义异常")
    @GetMapping("/applicationException")
    public AppResult testApplicationException() throws Exception {
        throw new ApplicationException("这是一个自定义的ApplicationException...");
    }

    @ApiOperation("测试传参")
    @GetMapping("/helloByName")
    public String testHelloByName(@ApiParam("名字") String name){
        return "hello,"+name;
    }
}
